package com.example.as_sum.expand;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.TextView;

import com.example.as_sum.R;
import com.example.as_sum.activity.RootActivity;
import com.example.as_sum.entity.ShopInfo;
import com.example.as_sum.entity.StoreInfo;
import com.example.as_sum.util.Log;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ExpandListViewActivirt extends RootActivity {

    @Bind(R.id.expandListview)
    ExpandableListView expandListview;
    @Bind(R.id.expandlstview_check_all)
    CheckBox expandlstviewCheckAll;
    @Bind(R.id.expandlstview_tv_money)
    TextView expandlstviewTvMoney;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_expand_list_view_activirt);
        ButterKnife.bind(this);
        initData();
        initView();
    }

    private void initData() {
        mStoreInfo=new ArrayList<>();
        List<ShopInfo> shops;
        for (int x=0;x<5;x++){
            StoreInfo store=new StoreInfo();
            store.setSid(100+x);
            store.setName("商铺"+x);
            shops=new ArrayList<>();
            for (int i=0;i<x+1;i++){
                ShopInfo shop=new ShopInfo();
                shop.setSname("商品"+i);
                shop.setPrice(10+10*i);
                shop.setSinfo("这是介绍"+i);
                shops.add(shop);
            }
            store.setShopInfos(shops);
            mStoreInfo.add(store);

        }
    }

    private List<StoreInfo> mStoreInfo;
    private void initView() {
        ExpandListVIewAdapter addpter=new ExpandListVIewAdapter(this,mStoreInfo);
        expandListview.setAdapter(addpter);
        expandListview.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
                Log.e("-------->","OnChildClick");
                return false;
            }
        });
        expandListview.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                Log.e("-------->","OnGroupClick,下标："+groupPosition);
                if(parent.isGroupExpanded(groupPosition)){
                    parent.collapseGroup(groupPosition);
                    Log.e("-------->","OnGroupClick：合拢");
                }else{
                    parent.expandGroup(groupPosition);
                    Log.e("-------->","OnGroupClick:展开");
                }
                return true;//一定要返回true，否则有异想不到的效果
            }
        });
    }

    @OnClick(R.id.expandlstview_check_all)
    public void onClick() {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }
}
